package com.zx.erp.purchase.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zx.erp.purchase.bean.CBrand;
import com.zx.erp.purchase.service.CBrandService;
import com.zx.erp.sys.bean.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者信息
 * @since 2021-11-10
 */
@Controller
@RequestMapping("/purchase/cbrand")
public class CBrandController {

    @Autowired
    private CBrandService service;

    @RequestMapping("/cblist")
    public String cbList(Model model, CBrand cBrand, @RequestParam(value = "pageno", defaultValue = "1") Integer
            pageNo){
        Integer pageSize = 6;
        Page<CBrand> pageInfo = service.getBrandListByCondition(cBrand, pageNo, pageSize);
        model.addAttribute("cbpage",pageInfo);
        return "forward:/purchase/brand/brandList.html";
    }

    @RequestMapping("/doAdd")
    public String doAdd(CBrand cBrand){
        boolean b = service.brandAdd(cBrand);
        return "redirect:/purchase/cbrand/cblist";
    }

    @RequestMapping("/goupdate/{brandId}")
    public String goupdate(@PathVariable(value = "brandId") Integer brandId, Model model){
        CBrand brand = service.getOneBrandByCondition(brandId);
        model.addAttribute("cbrand",brand);
        return "forward:/purchase/brand/brandUpdate.html";
    }

    @RequestMapping("/remov/{brandId}")
    public String remov(@PathVariable(value = "brandId") Integer brandId ){
        CBrand brand = service.getOneBrandByCondition(brandId);
        Integer brandStatus = brand.getBrandStatus();
        if(brandStatus==1){
            brand.setBrandStatus(2);
        }else{
            brand.setBrandStatus(1);
        }
        boolean b = service.brandUpdate(brand);
        return "redirect:/purchase/cbrand/cblist";
    }

}

